package com.jfinal.ext.ueditor.config;

import com.jfinal.kit.StrKit;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.List;

/**
 * @author Timor
 * @version 1.0
 * @date 2023/01/05 06:34:33
 */
public class ActionConfig implements IActionConfig {
    private String actionName = null;
    private String urlPrefix = "";
    private List<String> allowFiles = Collections.emptyList();


    @Override
    public String getActionName() {
        return actionName;
    }

    public void setActionName(String actionName) {
        this.actionName = actionName;
    }

    @Override
    public String getUrlPrefix() {
        return urlPrefix;
    }

    public void setUrlPrefix(String urlPrefix) {
        if (StrKit.notBlank(urlPrefix)) {
            this.urlPrefix = urlPrefix;
        }
    }


    @Override
    public @NotNull List<String> getAllowFiles() {
        return allowFiles;
    }

    public void setAllowFiles(String allowFile) {
        if (StrKit.notBlank(allowFile)) {
            this.allowFiles = List.of(allowFile);
        }
    }

    public void setAllowFiles(List<String> allowFiles) {
        if (null != allowFiles) {
            final List<String> items = allowFiles.stream()
                    .filter(StrKit::notBlank).toList();

            if (!allowFiles.isEmpty()) {
                this.allowFiles = items;
            }
        }
    }
}
